package com.my.home.common.Base;

import com.my.home.common.intercepter.LogIntercepter;
import com.my.home.common.shiro.ShiroUser;
import com.my.home.common.utils.CustomStringEditor;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Al Sah-him on 2018/5/28.
 */
public class BaseController {
    protected static final Logger logger= LoggerFactory.getLogger(LogIntercepter.class);
    //log

    //前台路径
    public static final String FRONT_PATH="front";

    //管理路径

    @InitBinder
    public void initBinder(ServletRequestDataBinder binding){
        //自动转换日期
        binding.registerCustomEditor(Date.class,new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),true));

        //防止xss攻击
        binding.registerCustomEditor(String.class,new CustomStringEditor());
    }

    /**
     * 获取当前登录用户
     * @return
     */
    public ShiroUser getCurrentUser(){
        return (ShiroUser) SecurityUtils.getSubject().getPrincipal();
    }


}
